<?php


namespace app\common\controller;


use support\utils\RandomUtil;
use support\utils\TenantUtil;

/**
 * Class UploadController
 * @package app\platform\controller
 */
class UploadController extends BaseController
{
    public function uploadFile()
    {
        $file = request()->file("file");
        $folderName = input("folderName", "default");
        $date = date("Ymd");
        $uuid = RandomUtil::UUID();
        $platform = "platform";
        if ($tid = TenantUtil::getTenantId()) {
            $platform = $tid;
        }
        $path = "/upload/{$platform}/{$folderName}/{$date}/{$uuid}" . "." . $file->getUploadExtension();
        $filePath = public_path() . $path;
        if ($file && $file->isValid()) {
            $file->move($filePath);
        }
        return $this->success([
            'fileUploadPath' => "//" . request()->host() . $path
        ]);
    }
}